package com.ruoyi.sso.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sso.domain.SsoWxUserUrl;
import com.ruoyi.sso.service.ISsoWxUserUrlService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户与物管关系Controller
 * 
 * @author zsj
 * @date 2020-01-07
 */
@Controller
@RequestMapping("/sso/wxUrl")
public class SsoWxUserUrlController extends BaseController
{
    private String prefix = "sso/wxUrl";

    @Autowired
    private ISsoWxUserUrlService ssoWxUserUrlService;

    @RequiresPermissions("sso:wxUrl:view")
    @GetMapping()
    public String wxUrl()
    {
        return prefix + "/wxUrl";
    }

    /**
     * 查询用户与物管关系列表
     */
    @RequiresPermissions("sso:wxUrl:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SsoWxUserUrl ssoWxUserUrl)
    {
        startPage();
        List<SsoWxUserUrl> list = ssoWxUserUrlService.selectSsoWxUserUrlList(ssoWxUserUrl);
        return getDataTable(list);
    }

    /**
     * 导出用户与物管关系列表
     */
    @RequiresPermissions("sso:wxUrl:export")
    @Log(title = "用户与物管关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SsoWxUserUrl ssoWxUserUrl)
    {
        List<SsoWxUserUrl> list = ssoWxUserUrlService.selectSsoWxUserUrlList(ssoWxUserUrl);
        ExcelUtil<SsoWxUserUrl> util = new ExcelUtil<SsoWxUserUrl>(SsoWxUserUrl.class);
        return util.exportExcel(list, "wxUrl");
    }

    /**
     * 新增用户与物管关系
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户与物管关系
     */
    @RequiresPermissions("sso:wxUrl:add")
    @Log(title = "用户与物管关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SsoWxUserUrl ssoWxUserUrl)
    {
        return toAjax(ssoWxUserUrlService.insertSsoWxUserUrl(ssoWxUserUrl));
    }

    /**
     * 修改用户与物管关系
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SsoWxUserUrl ssoWxUserUrl = ssoWxUserUrlService.selectSsoWxUserUrlById(id);
        mmap.put("ssoWxUserUrl", ssoWxUserUrl);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户与物管关系
     */
    @RequiresPermissions("sso:wxUrl:edit")
    @Log(title = "用户与物管关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SsoWxUserUrl ssoWxUserUrl)
    {
        return toAjax(ssoWxUserUrlService.updateSsoWxUserUrl(ssoWxUserUrl));
    }

    /**
     * 删除用户与物管关系
     */
    @RequiresPermissions("sso:wxUrl:remove")
    @Log(title = "用户与物管关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ssoWxUserUrlService.deleteSsoWxUserUrlByIds(ids));
    }
}
